import axios from 'axios'

const fetch = axios.create({
    baseURL: '/api',
    timeout: 30000
})

const cancelLoading = (config) => {

}

//请求拦截器
fetch.interceptors.request.use(req => {
    return req
}, (error) => {
    return Promise.reject(error)
})


//响应拦截器
fetch.interceptors.response.use(
    config => {
        try {
            const code = config.data.code
            // 成功处理
            if (code != 0) {

                return Promise.reject(config)
            } else {
                return config.data
            }
        } finally {
            cancelLoading(config)
        }
    },
    (error) => {
        try {
            // 失败处理
            if (error?.response?.status == 401) {

            }
            return Promise.reject(error)
        } finally {
            cancelLoading(error)
        }
    }
)


export default fetch


